#include "stdafx.h"
#include "InputLayouts.h"
#include "LoadShader.h"
#include "GlobalAppData.h"

#include "Renderer.h"

using namespace mgfx;

VertexFormatID VertexPosition::VertexFormat        = -1;
VertexFormatID VertexPositionTexture::VertexFormat = -1;
VertexFormatID VertexPositionNormalTangentTexture::VertexFormat = -1;
VertexFormatID VertexParticle::VertexFormat = -1;

void InputLayouts::init()
{
	Renderer * rdr = Renderer::Instance;

	const VFAttribute positionFormat[] = 
	{
		{ VFAttribute::POSITION, 0, VFAttribute::FLOAT, 3 },
	};
	VertexPosition::VertexFormat = rdr->addVertexFormat(positionFormat, ARRAYSIZE(positionFormat),
		loadShaderFromFile("LayoutPosition.fx"));

	const VFAttribute positionTextureFormat[] = 
	{
		{ VFAttribute::POSITION, 0, VFAttribute::FLOAT, 3 },
		{ VFAttribute::TEXCOORD, 0, VFAttribute::FLOAT, 2 },
	};
	VertexPositionTexture::VertexFormat = rdr->addVertexFormat(positionTextureFormat, ARRAYSIZE(positionTextureFormat),
		loadShaderFromFile("LayoutPositionTexture.fx"));

	const VFAttribute posNormTanTexFormat[] = 
	{
		{ VFAttribute::POSITION, 0, VFAttribute::FLOAT, 3 },
		{ VFAttribute::NORMAL, 0, VFAttribute::FLOAT, 3 },
		{ VFAttribute::TANGENT, 0, VFAttribute::FLOAT, 3 },
		{ VFAttribute::TEXCOORD, 0, VFAttribute::FLOAT, 2 },
	};
	VertexPositionNormalTangentTexture::VertexFormat = rdr->addVertexFormat(posNormTanTexFormat, ARRAYSIZE(posNormTanTexFormat),
		loadShaderFromFile("LayoutPositionNormalTangentTexture.fx"));

	const VFAttribute particleFormat[] = 
	{
		{ VFAttribute::POSITION, 0, VFAttribute::FLOAT, 3 },
		{ VFAttribute::TEXCOORD, 0, VFAttribute::FLOAT, 2 },
		{ VFAttribute::TEXCOORD, 1, VFAttribute::FLOAT, 1 },
		{ VFAttribute::TEXCOORD, 2, VFAttribute::FLOAT, 1 },
	};
	VertexParticle::VertexFormat = rdr->addVertexFormat(particleFormat, ARRAYSIZE(particleFormat),
		loadShaderFromFile("LayoutParticle.fx"));

	//{
	//	const D3D11_INPUT_ELEMENT_DESC particleLayout[] =
	//	{
	//		{ "POSITION",  0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0 },
	//		{ "NORMAL",  0, DXGI_FORMAT_R32G32B32_FLOAT,   0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	//		{ "TANGENT",  0, DXGI_FORMAT_R32G32B32_FLOAT,  0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	//		{ "TEXCOORD",  0, DXGI_FORMAT_R32G32_FLOAT,    0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	//	};

	//	ID3DX11EffectPass * pass = Renderer::Instance->getShaderEffectPass(HLSLEffect::createFromFile("LayoutParticle.fx")->Shader);
	//	pass->GetVertexShaderDesc(&vsPassDesc);
	//	vsPassDesc.pShaderVariable->GetShaderDesc(vsPassDesc.ShaderIndex, &vsDesc);

	//	//HR(device->CreateInputLayout( particleLayout, ARRAYSIZE( particleLayout ), vsDesc.pBytecode, vsDesc.BytecodeLength, &VertexParticle::InputLayout ) );
	//}
}
